package com.ly.config;


import com.ly.util.ExChangeNameUtil;
import com.ly.util.QueueNameUtil;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 李岩
 * @date 2022/1/11-8:59
 * @describe
 */
@Configuration
public class FanoutConfig {
    //队列 起名：TestQueue
    @Bean
    public Queue FanoutQueueProd() {
        //一般设置一下队列的持久化就好,其余两个就是默认false
        return new Queue(QueueNameUtil.FANOUT_QUEUE_NAME_PROD,true);
    }
    @Bean
    public Queue FanoutQueueUser() {
        //一般设置一下队列的持久化就好,其余两个就是默认false
        return new Queue(QueueNameUtil.FANOUT_QUEUE_NAME_USER,true);
    }
    //Direct交换机 起名：TestDirectExchange
    @Bean
    FanoutExchange FanoutExchange() {
        return new FanoutExchange(ExChangeNameUtil.FANOUT_EXCHANGE_ORDER,true,false);
    }
    //绑定  将队列和交换机绑定, 并设置用于匹配键：TestDirectRouting
    @Bean
    Binding bindingFanoutOne() {
        return BindingBuilder.bind(FanoutQueueProd()).to(FanoutExchange());
    }
    @Bean
    Binding bindingFanoutTwo() {
        return BindingBuilder.bind(FanoutQueueUser()).to(FanoutExchange());
    }
}

